﻿using System;
using System.Windows;
using Microsoft.Phone.Tasks;
using WindowsPhoneEssentials.Diagnostics;

namespace WindowsPhoneEssentials
{
    public partial class WebPageView
    {
        private string url;

        public WebPageView()
        {
            InitializeComponent();
            ApplicationTitle.Text = Information.GetAppAttribute("Title").ToUpper();
        }

        private void ViewInIE(object sender, EventArgs e)
        {
#if WINDOWS_PHONE71
            new WebBrowserTask
            {
                Uri = new Uri(url, UriKind.Absolute)
            }.Show();
#else
                new WebBrowserTask
                {
                    URL = url
                }.Show();
#endif
            NavigationService.GoBack();
        }

        private void PhoneApplicationPageLoaded(object sender, RoutedEventArgs e)
        {
            url = NavigationContext.QueryString["Page"];
            if (!url.StartsWith("http"))
                url = "http://" + url;
            browser.Navigate(new Uri(url, UriKind.Absolute));

            bool showAppBar;
            if (NavigationContext.QueryString.ContainsKey("ShowAppBar") && bool.TryParse(NavigationContext.QueryString["ShowAppBar"], out showAppBar))
                ApplicationBar.IsVisible = showAppBar;
        }
    }
}